#include <cassert>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;

template<typename T>
class Image{
  const int R, C;
  vector<vector<T> > img;
public:
  Image(int tr, int tc) : R(tr), C(tc), img(R) {
    for(int r = 0; r < R; ++r){
      img[r].resize(C);
    }
  }

  void set(int r, int c, T t){
    img[r][c] = t;
  }

  T get(int r, int c) const {
    return img[r][c];
  }

  void rotate_left90(Image<T>& dst) const {
    assert(R == dst.C);
    assert(C == dst.R);
    // TODO
  }
};

uint8_t read_byte(){
  return 0; // TODO
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  for(int R, C; cin >> R >> C && cin.get();){
    // cout << "# R=" << R << " C=" << C << endl;
    Image<uint32_t> src(R, C), dst(C, R);
    for(int r = 0; r < R; ++r){
      for(int c = 0; c < C; ++c){
        uint8_t aa = read_byte();
        uint8_t bb = read_byte();
        uint8_t gg = read_byte();
        uint8_t rr = read_byte();
        uint32_t x = (aa << 24) | (bb << 16) | (gg << 8) | rr;
        // cout << "# read " << r << ' ' << c << endl;
        src.set(r, c, x);
      }
    }
    src.rotate_left90(dst);
    cout << dec << C << ' ' << R << '\n';
    cout << hex << uppercase << setfill('0');
    for(int r = 0; r < C; ++r){
      for(int c = 0; c < R; ++c){
        cout << setw(8) << dst.get(r, c) << (c < R-1 ? ' ' : '\n');
      }
    }
  }
  cout << flush;
}
